﻿<UserControl x:Class="LevelEditor.View.UserControls.LayersPanel"
             Name="LayersControlPanel"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:cmd="clr-namespace:LevelEditor.Controllers"
             xmlns:px="clr-namespace:LevelEditor.Utils.ImageSnappingToPixels"
             xmlns:ut="clr-namespace:LevelEditor.Utils"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UIElement.CommandBindings>
        <CommandBinding Command="{x:Static cmd:AppCommands.DeleteGameSpriteCommand}" CanExecute="DeleteGameSpriteCmd_CanExecute" />
    </UIElement.CommandBindings>
    <FrameworkElement.Resources>
        <ResourceDictionary>
            <DataTemplate x:Key="LayerTemplateHeader">
                <DockPanel Margin="0,0,0,0" LastChildFill="True">
                    <Border DockPanel.Dock="Left" FrameworkElement.Margin="0,2,2,0" UIElement.SnapsToDevicePixels="True">
                        <px:Bitmap Source="/Assets/UI/ico_layers.png"  />
                    </Border>
                    <CheckBox Name="ItemLocked" FrameworkElement.Margin="1,2,2,0" DockPanel.Dock="Right" ToggleButton.IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type TreeViewItem}},Path=DataContext.IsItemLocked}" />
                    <CheckBox Name="ItemVisible" FrameworkElement.Margin="2,2,1,0" DockPanel.Dock="Right" ToggleButton.IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type TreeViewItem}},Path=DataContext.IsItemVisible}" />
                    <TextBlock FrameworkElement.Margin="1,0,0,0" TextBlock.Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type TreeViewItem}},Path=DataContext.Name}" />
                </DockPanel>
            </DataTemplate>
            <DataTemplate x:Key="LayerTemplateSpriteHeader">
                <DockPanel FrameworkElement.Margin="0,0,0,0" DockPanel.LastChildFill="True" UIElement.SnapsToDevicePixels="True">
                    <Border DockPanel.Dock="Left" FrameworkElement.Margin="0,2,2,0">
                        <px:Bitmap Source="/Assets/UI/ico_sprite.png"  />
                    </Border>
                    <CheckBox Name="ItemLocked" FrameworkElement.Margin="1,2,2,0" DockPanel.Dock="Right" ToggleButton.IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type TreeViewItem}},Path=DataContext.IsItemLocked}" />
                    <CheckBox Name="ItemVisible" FrameworkElement.Margin="2,2,1,0" DockPanel.Dock="Right" ToggleButton.IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type TreeViewItem}},Path=DataContext.IsItemVisible}" />
                    <TextBlock FrameworkElement.Margin="1,0,0,0" TextBlock.Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type TreeViewItem}},Path=DataContext.Name}" />
                </DockPanel>
            </DataTemplate>
            <Style Style.TargetType="{x:Type TreeViewItem}" Style.BasedOn="{StaticResource {x:Type TreeViewItem}}">
                <Setter Setter.Property="Control.HorizontalContentAlignment" Setter.Value="Center" />
                <Setter Setter.Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate ControlTemplate.TargetType="{x:Type TreeViewItem}">
                            <FrameworkTemplate.Resources>
                                <ResourceDictionary>
                                    <ut:LeftMarginMultiplierConverter Length="10" x:Key="lengthConverter"/>
                                </ResourceDictionary>
                            </FrameworkTemplate.Resources>
                            <StackPanel Name="Sp" FrameworkElement.UseLayoutRounding="True">
                                <Border Border.Background="{TemplateBinding Panel.Background}" Border.BorderThickness="{TemplateBinding Border.BorderThickness}" Border.BorderBrush="{TemplateBinding Border.BorderBrush}">
                                    <DockPanel Name="Dp" DockPanel.LastChildFill="True">
                                        <ToggleButton Name="Expander" DockPanel.Dock="Left" ButtonBase.ClickMode="Press" FrameworkElement.Margin="{Binding Converter={StaticResource lengthConverter},RelativeSource={RelativeSource TemplatedParent}}" ToggleButton.IsChecked="{Binding Path=IsExpanded,RelativeSource={RelativeSource TemplatedParent}}">
                                            <FrameworkElement.Style>
                                                <Style Style.TargetType="{x:Type ToggleButton}">
                                                    <Setter Setter.Property="UIElement.Focusable" Setter.Value="False" />
                                                    <Setter Setter.Property="FrameworkElement.Width" Setter.Value="16" />
                                                    <Setter Setter.Property="FrameworkElement.Height" Setter.Value="16" />
                                                    <Setter Setter.Property="Control.Template">
                                                        <Setter.Value>
                                                            <ControlTemplate ControlTemplate.TargetType="{x:Type ToggleButton}">
                                                                <Border Border.Padding="5,5,5,5" Border.Background="#00FFFFFF" FrameworkElement.Width="16" FrameworkElement.Height="16">
                                                                    <Path Name="ExpandPath" Shape.Fill="#00FFFFFF" Shape.Stroke="#FF989898">
                                                                        <Path.Data>
                                                                            <PathGeometry PathGeometry.Figures="M0,0L0,6L6,0z" />
                                                                        </Path.Data>
                                                                        <UIElement.RenderTransform>
                                                                            <RotateTransform RotateTransform.Angle="135" RotateTransform.CenterX="3" RotateTransform.CenterY="3" />
                                                                        </UIElement.RenderTransform>
                                                                    </Path>
                                                                </Border>
                                                                <ControlTemplate.Triggers>
                                                                    <Trigger Trigger.Property="UIElement.IsMouseOver" Trigger.Value="True">
                                                                        <Setter Setter.TargetName="ExpandPath" Setter.Property="Shape.Stroke" Setter.Value="#FF1BBBFA" />
                                                                        <Setter Setter.TargetName="ExpandPath" Setter.Property="Shape.Fill" Setter.Value="#00FFFFFF" />
                                                                    </Trigger>
                                                                    <Trigger Trigger.Property="ToggleButton.IsChecked" Trigger.Value="True">
                                                                        <Setter Setter.TargetName="ExpandPath" Setter.Property="UIElement.RenderTransform">
                                                                            <Setter.Value>
                                                                                <RotateTransform RotateTransform.Angle="180" RotateTransform.CenterX="3" RotateTransform.CenterY="3" />
                                                                            </Setter.Value>
                                                                        </Setter>
                                                                        <Setter Setter.TargetName="ExpandPath" Setter.Property="Shape.Fill" Setter.Value="#FF595959" />
                                                                        <Setter Setter.TargetName="ExpandPath" Setter.Property="Shape.Stroke" Setter.Value="#FF262626" />
                                                                    </Trigger>
                                                                </ControlTemplate.Triggers>
                                                            </ControlTemplate>
                                                        </Setter.Value>
                                                    </Setter>
                                                </Style>
                                            </FrameworkElement.Style>
                                        </ToggleButton>
                                        <Border Border.Name="Bd" FrameworkElement.HorizontalAlignment="Stretch" Border.Padding="{TemplateBinding Control.Padding}" UIElement.SnapsToDevicePixels="True">
                                            <ContentPresenter ContentPresenter.Name="PART_Header" ContentPresenter.Content="{TemplateBinding HeaderedContentControl.Header}" ContentPresenter.ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}" ContentPresenter.ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}" ContentPresenter.ContentTemplateSelector="{TemplateBinding HeaderedItemsControl.HeaderTemplateSelector}" ContentPresenter.ContentSource="Header" UIElement.SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                                        </Border>
                                    </DockPanel>
                                </Border>
                                <ItemsPresenter ItemsPresenter.Name="ItemsHost" FrameworkElement.Margin="0,0,0,0" UIElement.SnapsToDevicePixels="True" />
                            </StackPanel>
                            <ControlTemplate.Triggers>
                                <Trigger Trigger.Property="TreeViewItem.IsExpanded" Trigger.Value="False">
                                    <Setter Setter.TargetName="ItemsHost" Setter.Property="UIElement.Visibility" Setter.Value="Collapsed" />
                                </Trigger>
                                <Trigger Trigger.Property="ItemsControl.HasItems" Trigger.Value="False">
                                    <Setter Setter.TargetName="Expander" Setter.Property="UIElement.Visibility" Setter.Value="Hidden" />
                                </Trigger>
                                <Trigger Trigger.Property="TreeViewItem.IsSelected" Trigger.Value="True">
                                    <Setter Setter.TargetName="Dp" Setter.Property="Panel.Background" Setter.Value="#FFD2D2D2" />
                                    <Setter Setter.Property="TextElement.Foreground" Setter.Value="#FFFF0000" />
                                </Trigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Condition.Property="TreeViewItem.IsSelected" Condition.Value="True" />
                                        <Condition Condition.Property="Selector.IsSelectionActive" Condition.Value="False" />
                                    </MultiTrigger.Conditions>
                                    <Setter Setter.TargetName="Dp" Setter.Property="Panel.Background" Setter.Value="#FFD2D2D2" />
                                    <Setter Setter.Property="TextElement.Foreground" Setter.Value="#FFFF0000" />
                                </MultiTrigger>
                                <Trigger Trigger.Property="UIElement.IsEnabled" Trigger.Value="False">
                                    <Setter Setter.Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" Setter.Property="TextElement.Foreground" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </FrameworkElement.Resources>
    <DockPanel DockPanel.LastChildFill="True" FrameworkElement.Width="Auto">
        <Grid DockPanel.Dock="Top">
            <Rectangle FrameworkElement.Height="20" Shape.Fill="#FF2D2D2D" />
            <Label Control.Foreground="#FFFFFFFF">
                Layers
            </Label>
        </Grid>
        <Border DockPanel.Dock="Top" Border.BorderThickness="1" Border.BorderBrush="#FFEEEEEE" FrameworkElement.Margin="2">
            <DockPanel DockPanel.LastChildFill="True" FrameworkElement.HorizontalAlignment="Stretch" FrameworkElement.Width="Auto">
                <Border DockPanel.Dock="Right" FrameworkElement.Margin="0,4,2,0">
                    <px:Bitmap Source="/Assets/UI/ico_search.png" />
                </Border>
                <TextBox Name="SearchTB" DockPanel.Dock="Left" Control.BorderThickness="0" />
            </DockPanel>
        </Border>
        <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" Control.Background="#FFFFFFFF" FrameworkElement.Width="Auto">
            <StackPanel FrameworkElement.VerticalAlignment="Top" FrameworkElement.HorizontalAlignment="Stretch" FrameworkElement.Width="Auto">
                <TreeView Name="LayersTree" Control.Foreground="#FF0000FF" UIElement.AllowDrop="True" Control.BorderThickness="0">
                    <TreeViewItem Name="SceneLayer" HeaderedItemsControl.Header="Scene" TreeViewItem.IsExpanded="True" UIElement.AllowDrop="False">
                        <HeaderedItemsControl.HeaderTemplate>
                            <DataTemplate>
                                <DockPanel FrameworkElement.Margin="0,2,2,0" DockPanel.LastChildFill="True" FrameworkElement.UseLayoutRounding="True">
                                    <Border DockPanel.Dock="Right">
                                        <px:Bitmap Source="/Assets/ui/ico_lock.png"  />
                                    </Border>
                                    <Border FrameworkElement.Margin="0,1,2,0" DockPanel.Dock="Right">
                                        <px:Bitmap Source="/Assets/ui/ico_eye.png"  />
                                    </Border>
                                    <Border FrameworkElement.Margin="0,2,2,0" DockPanel.Dock="Left">
                                        <px:Bitmap Source="/Assets/ui/ico_scene.png"  />
                                    </Border>
                                    <TextBlock FrameworkElement.Margin="1,0,0,0" TextBlock.FontWeight="Bold" TextBlock.Text="{Binding}" />
                                </DockPanel>
                            </DataTemplate>
                        </HeaderedItemsControl.HeaderTemplate>
                    </TreeViewItem>
                </TreeView>
            </StackPanel>
        </ScrollViewer>
    </DockPanel>
</UserControl>
